//查询证券名称
function querySecuritiesName(flag) {
	var number = "";
	if (flag === "buy") {
		number = document.getElementById("securNum").value;
		document.getElementById("securName").value = "";
	} else {
		number = document.getElementById("saleSecurNum").value;
		document.getElementById("saleSecurName").value = "";
	}
	var options = {
		"stockCode" : number
	}
	var para = JSON.stringify(options);
	$.ajax({
		type : "POST",
		url : "/ThreeNewBoard/stockcode",
		data : para,
		crossDomain : true,
		async : true,
		contentType : "application/json",
		dataType : "json",
		success : function(result) {
			if (result.message === "SUCCESS") {
				// 查询到的数据
				var data = result.data
				if (flag === "buy") {
					document.getElementById("securName").value = data
							&& data.stockCodeName || "";
				} else {
					document.getElementById("saleSecurName").value = data
							&& data.stockCodeName || "";
				}

			} else {
				alert(result.data.promptMessage || "输入错误！");
			}
		}
	});
}
// 校验证券ID
function validSecurID(flag) {
	var value = "";
	if (flag === "buy") {
		document.getElementById("securNumError").innerText = "";
		value = document.getElementById("securNum").value;
	} else {
		document.getElementById("saleSecurNumError").innerText = "";
		value = document.getElementById("saleSecurNum").value;
	}
	if (!securIDValidator.test(value)) {
		if (flag === "buy") {
			document.getElementById("securNumError").innerText = "请输入正确的证券ID";
		} else {
			document.getElementById("saleSecurNumError").innerText = "请输入正确的证券ID";
		}
		return false;
	}
}
// 校验数量
function validCount(flag) {
	var value = "";
	if (flag === "buy") {
		document.getElementById("countError").innerText = "";
		value = document.getElementById("count").value;
	} else {
		document.getElementById("saleCountError").innerText = "";
		value = document.getElementById("saleCount").value;
	}
	if (!countValidator.test(value)) {
		if (flag === "buy") {
			document.getElementById("countError").innerText = "请输入正确的买入数量";
		} else {
			document.getElementById("saleCountError").innerText = "请输入正确的卖出数量";
		}

		return false;
	}
}
// 校验价格
function validPrice(flag) {
	var value = "";
	if (flag === "buy") {
		document.getElementById("priceError").innerText = "";
		value = document.getElementById("price").value;
	} else {
		document.getElementById("saleCountError").innerText = "";
		value = document.getElementById("salePrice").value;
	}
	if (!priceValidator.test(value)) {
		if (flag === "buy") {
			document.getElementById("priceError").innerText = "请输入正确的买入价格";
		} else {
			document.getElementById("salePriceError").innerText = "请输入正确的卖出价格";
		}

		return false;
	}
}
//查询用户详情
function queryUserInfo(from) {
	var options = {
		"accountNumber" : localStorage.accountNum,
		"token" : localStorage.token,
		"number": ""
	};
	$.ajax({
		type : "POST",
		url : "/ThreeNewBoard/queryuser",
		data : JSON.stringify(options),
		crossDomain : true,
		async : true,
		contentType : "application/json",
		dataType : "json",
		success : function(result) {
			if (result.message === "SUCCESS") {
				// data为请求到的数据
				var data = result.data;
				if(!from){
					$("#userName").html("");
					$("#userName").html("");
					$("#userName").html(data.userName);
					$("#balance").html(data.balance);
				}else{
					window.parent.parent.document.getElementById("balance").innerText="";
					window.parent.parent.document.getElementById("balance").innerText=data.userName;
					window.parent.parent.document.getElementById("balance").innerText=data.balance;
				}
			} else {
				alert("数据请求错误！");
			}
		}
	});
}
//校验密码
function validNewPsd(value,id){
	document.getElementById(id).innerText = "";
	if (!passwordValidator.test(value)) {
		document.getElementById(id).innerText = "密码以字母开头，长度在6-18之间，只能包含英文字母、数字和下划线。";
		return false;
	}
}
//确认密码
function confirmPsd(value,id,preId){
	document.getElementById(id).innerText = "";
	var psd = document.getElementById(preId).value;
	if (value !== psd) {
		document.getElementById(id).innerText = "两次输入密码不一致。";
		return false;
	}
}
//管理员修改密码
function modifyPwd() {
	var newPsd = document.getElementById("admNewPsd").value;
	var againNewPsd = document.getElementById("againNewPsd").value
	var newPsdError = document.getElementById("admNewPsdMsg").innerHTML;
	var againNewPsdError = document.getElementById("againNewPsdMsg").innerHTML;
	if(newPsd === ""){
		alert("请输入新密码。");
		return;
	}
	if(againNewPsd === ""){
		alert("请再次确认密码。");
		return;
	}
	if (newPsdError) {
		alert("密码不合法，请确认。");
		return;
	}
	if (againNewPsdError) {
		alert("两次输入密码不一致，请确认。");
		return;
	}
	closeWindow('modifyAdmPsdModal');
	var options = {
		"accountNumber" : localStorage.accountNum,
		"token" : localStorage.token,
		"newPassWord" : document.getElementById("admNewPsd").value,
		"number" : localStorage.accountNum
	};
	$.ajax({
		type : "POST",
		url : "/ThreeNewBoard/adminchpasswd",
		data : JSON.stringify(options),
		crossDomain : true,
		async : true,
		contentType : "application/json",
		dataType : "json",
		success : function(result) {
			var data = result.data;
			if (data.status) {
				// data为请求到的数据
				alert(data.promptMessage);
			} else {
				alert("数据请求错误！");
			}
		}
	});
}
//用户修改密码
function userModifyPwd() {
	var oldPsd = document.getElementById("userOldPsd").value;
	var newPsd = document.getElementById("userNewPsd").value;
	var againNewPsd = document.getElementById("againNewPsd").value
	var newPsdError = document.getElementById("userNewPsdMsg").innerHTML;
	var againNewPsdError = document.getElementById("againNewPsdMsg").innerHTML;
	if(oldPsd === ""){
		alert("请输入原始密码。");
		return;
	}
	if(newPsd === ""){
		alert("请输入新密码。");
		return;
	}
	if(againNewPsd === ""){
		alert("请再次确认密码。");
		return;
	}
	if (newPsdError) {
		alert("密码不合法，请确认。");
		return;
	}
	if (againNewPsdError) {
		alert("两次输入密码不一致，请确认。");
		return;
	}
	closeWindow('modifyUserPsdModal');
	var options = {
		"accountNumber" : localStorage.accountNum,
		"token" : localStorage.token,
	    "passWord":oldPsd,						//旧密码
	    "newPassWord":newPsd					//新密码
	};
	$.ajax({
		type : "POST",
		url : "/ThreeNewBoard/changepassword",
		data : JSON.stringify(options),
		crossDomain : true,
		async : true,
		contentType : "application/json",
		dataType : "json",
		success : function(result) {
			var data = result.data;
			if (data.status) {
				// data为请求到的数据
				alert(data.promptMessage);
			} else {
				alert(data.promptMessage);
			}
		}
	});
}
					